#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "MSTK.h"


#ifdef __cplusplus
extern "C" {
#endif
  /* This function detect boundary of the mesh.
     The information will be assigned to MEnt_GEntDim field.
     For surface mesh:
     a vertex is a corner (dimension 0) iff it has only one 
     neighbor face.
     an edge is on boundary (dimension 1) iff it has only one
     neighbour face.
     an vertex is on boundary (dimension 1) iff it is an endpoint
     of boundary edge.

     For volume mesh:
     a vertex is a corner (dimension 0) iff it has only one 
     neighbor face.
     an edge is on boundary (dimension 1) iff it has only one
     neighbour region.
     an vertex is on boundary (dimension 1) iff it is an endpoint
     of boundary edge.
     a face is on boundary (dimension 2) iff it has only one 
     nrighbor region.
     an edge is on boundary (dimension 2) iff it is on a boundary
     face
     a vertex is on boundaty (dimension 2) iff it is on a boundary 
     face
  */

int MESH_BuildBoundary(Mesh_ptr mesh) {
  int nf, nr;
  /* basic mesh information */
  nf = MESH_Num_Faces(mesh);
  nr = MESH_Num_Regions(mesh);
 
  if (nr) 
    MESH_Vol_BuildBoundary(mesh);
  else if(nf) 
    MESH_Surf_BuildBoundary(mesh);
  else {
    fprintf(stdout,"\nThis is not a valid mstk file for building boundary\n");
    exit(-1);
  }
  return 1;
}
  
#ifdef __cplusplus
}
#endif

